package com.example.constellation.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.bean.StarBean;
import com.example.constellation.utils.AssetsUtils;

import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class fg3guideradapter extends BaseAdapter {
    private final Map<String, Bitmap> contentlogomap;
    private Context context;
    private List<StarBean.StarinfoBean> mdata;

    public fg3guideradapter(Context context, List<StarBean.StarinfoBean> mdata) {
        this.context = context;
        this.mdata = mdata;
        contentlogomap = AssetsUtils.getContentlogomap();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int position) {
        return mdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewholder holder=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.fg3gvitem,null);
            holder=new viewholder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (viewholder) convertView.getTag();
        }
        //获取指定位置的数据
        StarBean.StarinfoBean bean = mdata.get(position);
        holder.fg3txt.setText(bean.getName());
        //通过名称，获取内存中的图片
        Bitmap bitmap = contentlogomap.get(bean.getLogoname());
        holder.fg3iv.setImageBitmap(bitmap);
        return convertView;
    }

    class viewholder{
        CircleImageView fg3iv;
        TextView fg3txt;

        public viewholder(View view) {
            fg3iv = view.findViewById(R.id.fg3iv);
            fg3txt = view.findViewById(R.id.fg3txt);
        }
    }
}
